package operation.action;

import operation.action.Goods_Operation;
import uesr.Goods;

import java.util.LinkedList;
import java.util.Scanner;

public class UpdateGoods implements Goods_Operation {
    @Override
    public void work(LinkedList<Goods> goods) {
        System.out.println("请输入你要修改的商品的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        Goods[] tmp = (Goods[])goods.toArray();
        int i = 0;
        for (i = 0; i < goods.size();i++) {
            if (tmp[i].name.equals(name)) {
                System.out.println(tmp[i].name + tmp[i].price + tmp[i].count);
                System.out.println("请输入商品新的信息");
                System.out.println("新的商品名字");
                tmp[i].name = scanner.next();
                System.out.println("新的商品价格");
                tmp[i].price = scanner.nextInt();
                System.out.println("新的商品数量");
                tmp[i].count = scanner.nextInt();
            }
        }
        if (i == goods.size()) {
            System.out.println("查无此商品");
        }

    }



}
